package il.ac.bgu.cs.heuristics.utils;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public final class StringUtils{

	private StringUtils() {
	} // no instantiation

	public static boolean containsText(String s) {
		return s != null && !s.isEmpty();
	}

	public static <E> String toCommaDelimitedString(Collection<E> col) {
		final StringBuilder sb = new StringBuilder();
		for (final Iterator<E> it = col.iterator(); it.hasNext();) {
			sb.append(it.next());
			if (it.hasNext()) {
				sb.append(',');
			}
		}
		return sb.toString();
	}

	public static <E> List<String> prefixElementsWith(List<E> list,
	        String prefix) {
		final List<String> prefixed = CollectionUtils.newArrayList(list.size());
		for (E e : list) {
			prefixed.add(prefix + e.toString());
		}
		return prefixed;
	}

}
